<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="新增附件" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<script src="/js/popup_ext.js"></script>
<script src="/js/jquery.js"></script>
<script src="/js/EkUpload.js"></script>
<script language="javascript">
	function doCancel(){
		parent.ClosePop();
	}
	function doStart(){
		var files=document.getElementById("fileName").files;
		if(files.length>0){
			var lowerFn=files[0].name.toLowerCase();
			if(lowerFn.endWith(".exe") || lowerFn.endWith(".bat") || lowerFn.endWith(".com") || lowerFn.endWith(".jsp") || lowerFn.endWith(".htm") || lowerFn.endWith(".html")){
				ShowAlert('提示框','不能上传.exe、.bat、.com、.jsp、.htm或.html格式的文件！',200,100);
			}else{
				document.getElementById("startButton").disabled=true;
				document.getElementById("pauseButton").disabled=false;
				
				//不给修改,否则upload后插入数据有可能有偏差
				document.getElementById("fileName").disabled=true;
				document.getElementById("mark").disabled=true;
				
				EkUpload.upload(
					files,
					function(msg){
						ShowAlert('提示框',msg,200,100);
					},
					null,
					showUploadProc,
					doInsertRecord
				);
			}
		}else{
			ShowAlert('提示框','请选择要上传的文件！',200,100);
		}
	}
	function showUploadProc(total,ci){
		var totalStr=parseFileSize(total);
		var ciStr=parseFileSize(ci);
		var percentStr;
		if(total!=0){
			percentStr=(Math.round(ci*100/total)).toString()+"%";
			if(percentStr!="0%"){
				document.getElementById("proTd").style.width=percentStr;
				document.getElementById("percentTd").innerHTML=percentStr;
				if(ci==total){//100%
					document.getElementById("remainTd").style.display="none";
				}else{
					document.getElementById("remainTd").style.display="";
				}
			}
		}
		document.getElementById("proSpan").innerHTML="已传"+ciStr+"，总文件大小"+totalStr;
	}
	function doInsertRecord(fileName){
		fileName=encodeURIComponent(fileName);
		var agentId="${agentId}";
		var agentType="${agentType}";
		var code="${code}";
		var mark=encodeURIComponent(document.getElementById("mark").value);
		window.location="/business/AccessoryInsertRecord.ihtm?agent_id="+agentId+"&agent_type="+agentType+"&code="+code+"&file_name="+fileName+"&mark="+mark;
	}
	function doPause(){
		if(document.getElementById("pause_flag").value==""){
			EkUpload.pause();
			document.getElementById("pause_flag").value="PAUSE";
			document.getElementById("pauseButton").value="继续";
		}else{
			EkUpload.restart();
			document.getElementById("pause_flag").value="";
			document.getElementById("pauseButton").value="暂停";
		}
	}
	function showMe(){
		if(checkNavigator()[0]!="msie"){
			document.getElementById("fileName").className="";
		}
	}
	function keepAlive(){
		var currentTime=new Date();
		var xmlHttp=createXMLHttpRequest();
		xmlHttp.open("GET", "/Foot.ihtm?random="+currentTime.getTime(),true);
		xmlHttp.send(null);
		setTimeout("keepAlive()",1000*60*10);
	}
	function browseFolder(){
		try{
			var shell = new ActiveXObject("Shell.Application");
			var folder = shell.BrowseForFolder(0, "请选择目录", 64, 17);//起始目录为：我的电脑
			//var folder = shell.BrowseForFolder(0,"请选择目录",0); //起始目录为：桌面
			if(folder!=null){
				folder = folder.items(); // 返回 FolderItems 对象
            	folder = folder.item(); // 返回 Folderitem 对象
            	folder = folder.Path;   // 返回路径
            	if (folder.charAt(folder.length - 1) != "\\") {
                	folder = folder + "\\";
            	}
            	document.getElementById("customPath").value = folder;
			}
		}catch(e){
			ShowAlert('提示框',e.message,200,100);
		}
	}
</script>
</head>
<body oncontextmenu="return false" scroll="no" onLoad="showMe();keepAlive();" class="sheet modal-dialog" style=" padding-top:10px;">
<div class="sheet-main" style="width:530px;" id="bodyDiv">
  <div class="sheet-list" style="width:100%;">
    <div class="modal-main search-business">
    	<div style="width:100%;">
 			<c:set var="pageTopTitle" value="新增附件" />
			<%@ include file="../inc/PageTop.jsp"%>
			
			<div class="blank12"></div> 
			<table border="0" cellspacing="1" cellpadding="1" align="center" class="table-0" >
				<tr>			   	
			      	<th style="width:20%">上传到服务器：</th>
			      	<td style="width:80%">
						<input type="file" onKeyUp="goNextInput('mark');" name="fileName" id="fileName" style="width:220px" class="TextBox">
			     	</td>
				</tr>
				<tr>
			      	<th>文件说明：</th>
			      	<td>
			      		<input type="text" maxlength="50" name="mark" id="mark" style="width:220px" class="TextBox">
			     	</td>
				</tr>
				<tr>
			      	<th>进度：</th>
			      	<td>
						<table border="0" id="proTbl" class="table-c">
							<tr>
								<td style="width:84%">
									<table height="20" border="1" class="table-c">
										<tr>
											<td id="proTd" name="proTd" style="width:1px;" bgcolor="#3333cc"></td>
											<td id="remainTd" name="remainTd" bgcolor="#cccccc" style="width:100%">&nbsp;</td>
										</tr>
									</table>
								</td>
								<td id="percentTd" name="percentTd">0%</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
		      		<th>状态：</th>
					<td id="proSpan" name="proSpan">未上传</td>
				</tr>
			</table>
			</div>
		</div>
	</div>
	<div class="modal-buttom">
		<input type="button" class="buttom-a" value=" 上 传 " id="startButton" onClick="doStart();">
		<input type="button" class="buttom-a" value=" 暂 停 " id="pauseButton" onClick="doPause();" disabled="true">
		<input type="button" class="buttom-a" value=" 取 消 " onClick="doCancel();" >	
		<input type="hidden" id="pause_flag" value="">
	</div>
</div>
</body>
</html>